//
//  HX_DetailView.m
//  UI22-阿里星球（音乐）
//
//  Created by 韩旭 on 16/8/15.
//  Copyright © 2016年 lanou. All rights reserved.
//
#import "UIImageView+WebCache.h"
#import "HX_DetailView.h"
#import "SelfSizeTools.h"
#import "HX_TableViewCustom.h"
#import "AFNetworking.h"
#import "HX_ActionModel.h"
#import "HX_TableViewDetailModel.h"
@interface HX_DetailView ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) NSMutableArray *arrDataSource;

@property (nonatomic, strong) UIView *viewTitle;
@property (nonatomic, strong) UIButton *btnBack;
@property (nonatomic, strong) UIButton *btnSan;
@property (nonatomic, strong) UIButton *music;
@property (nonatomic, strong) UILabel *lableTitle;
@property (nonatomic, strong) UIImageView *imageTitle;
@property (nonatomic, strong) UILabel *lableName;
@property (nonatomic, strong) UIImageView *imageHead;
@property (nonatomic, strong) UILabel *lableDetail;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *viewTableHead;

@end

@implementation HX_DetailView
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (NSMutableArray *)arrDataSource {
    if (!_arrDataSource) {
        _arrDataSource = [NSMutableArray array];
    }
    return _arrDataSource;
}
- (void)creatTitleView {
    self.viewTitle = [[UIView alloc] initWithFrame:CGRectMake(0, 20, kWidth, 44)];
    _viewTitle.backgroundColor = [UIColor colorWithWhite:0.667 alpha:0.283];
    [self.view addSubview:_viewTitle];
    self.btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.btnBack setImage:[UIImage imageNamed:@"xiangzuo"] forState:UIControlStateNormal];
    _btnBack.frame = CGRectMake(0, 0, 30, 30);
    _btnBack.center = CGPointMake(_viewTitle.frame.size.width * 0.07, _viewTitle.frame.size.height / 2);
    [self.viewTitle addSubview:_btnBack];
    [_btnBack addTarget:self action:@selector(creatBackAdd:) forControlEvents:UIControlEventTouchUpInside];
    self.lableTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 30)];
    self.lableTitle.center = CGPointMake(self.viewTitle.frame.size.width / 2, _viewTitle.frame.size.height / 2);
    CGRect frame = self.lableTitle.frame;
    frame.size.width = [SelfSizeTools selfSizeHeightWithString:_lableTitle.text Width:30 Font:[UIFont systemFontOfSize:17]];
    self.lableTitle.frame = frame;
    [self.viewTitle addSubview:_lableTitle];
    self.btnSan = [UIButton buttonWithType:UIButtonTypeCustom];
    _btnSan.frame = CGRectMake(0, 0, 30, 30);
    _btnSan.center = CGPointMake(_viewTitle.frame.size.width * 0.84, _viewTitle.frame.size.height / 2);
    [self.viewTitle addSubview:_btnSan];
    [_btnSan setImage:[UIImage imageNamed:@"sandian"] forState:UIControlStateNormal];
    self.music = [UIButton buttonWithType:UIButtonTypeCustom];
    self.music.frame = CGRectMake(0, 0, 30, 30);
    self.music.center = CGPointMake(_btnSan.frame.size.width + _btnSan.frame.origin.x + 20, _viewTitle.frame.size.height / 2);
    [_music setImage:[UIImage imageNamed:@"yinyue"] forState:UIControlStateNormal];
    [self.viewTitle addSubview:_music];
}
- (void)creatBackAdd:(UIButton *)btn {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self handModel];

    [self creatImageHead];
    [self creatTableView];
    [self creatTitleView];
}
- (void)handModel {
    AFHTTPSessionManager *manger = [AFHTTPSessionManager manager];
    NSString *url = [NSString stringWithFormat:@"http://api.dongting.com/song/album/%@", self.stringUrl];
    [manger GET:url parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dicAll =  responseObject;
        NSDictionary *dicData = dicAll[@"data"];
        NSArray *arrSongList = dicData[@"songList"];
      NSString *sr = dicData[@"picUrl"];
        [self.imageHead sd_setImageWithURL:[NSURL URLWithString:sr]];
        for (NSDictionary *dic in arrSongList) {
            HX_TableViewDetailModel *va =    [HX_TableViewDetailModel hx_BasemodelWithDic:dic];
            [self.arrDataSource addObject:va];
        }
        [_tableView reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        
    }];
}
- (void)creatImageHead {
    self.viewTableHead = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 300)];
    [self.view addSubview:_viewTableHead];
    self.imageHead = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 250)];
    _imageHead.backgroundColor = [UIColor greenColor];
    [self.viewTableHead addSubview:_imageHead];
    NSArray *arr = @[@"收藏", @"评论", @"分享"];
    for (int i = 0; i < 3; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(_viewTableHead.frame.size.width / 3 * i, _imageHead.frame.size.height, _viewTableHead.frame.size.width / 3, 50);
        btn.backgroundColor = COLORAUTO;
        [btn setTitle:arr[i] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:13];
        [self.viewTableHead addSubview:btn];
    }
    
}
- (void)creatTableView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, -20, kWidth, kHeight) style:0];
    self.tableView.delegate = self;
    _tableView.backgroundColor = [UIColor blackColor];
    self.tableView.dataSource = self;
    [self.view addSubview:_tableView];
    _tableView.tableHeaderView = _viewTableHead;
    [_tableView registerNib:[UINib nibWithNibName:@"HX_TableViewCustom" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"ce"];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _arrDataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HX_TableViewCustom *cell = [tableView dequeueReusableCellWithIdentifier:@"ce"];
    cell.lableName.text = [self.arrDataSource[indexPath.row] name];
    cell.lableRefule.text = [self.arrDataSource[indexPath.row] alias];
    NSString *string = [self.arrDataSource[indexPath.row] name];
    NSString *string2 = [self.arrDataSource[indexPath.row] singerName];
    cell.lableDvd.text = [NSString stringWithFormat:@"%@ - %@", string2, string];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    //    scrollView.contentOffset.y/400;
    CGFloat down =(0 - scrollView.contentOffset.y) ;
    
    if (down < 0 ) {
        return;
    }
    //
    
    CGRect rect = self.imageHead.frame;
    rect.size.height =  1 * down + 250;
    self.imageHead.frame = rect;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
